package com.kikoulol.jarmoryextractor;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import com.kikoulol.jarmoryextractor.utils.Utils;


public class Item {

	Element itemXml;
	
	private String id;
	private String name;
	private String icon;
	private String heroic;
	private String overallQualityId;
	private String bonding;
	private String classId;
	private String equipData;
	private String damageData;
	private String bonusStrength;
	private String bonusStamina;
	private String armor;
	private String socketData;
	private String durability;
	private String requiredLevel;
	private String itemLevel;
	private String bonusDefenseSkillRating;
	private String bonusHitRating;
	private String bonusDodgeRating;
	private String itemSource;

	public Item(String armoryUrl) throws IOException, ParserConfigurationException, SAXException {
		String xml = Utils.getArmoryXml(armoryUrl);
		try {
			itemXml = Utils.getXmlRootElement(xml);
		}
		catch (Exception e) {
			File fileToRemove = new File(Utils.getLocalUrl(armoryUrl));
			fileToRemove.delete();
			xml = Utils.getArmoryXml(armoryUrl);
			itemXml = Utils.getXmlRootElement(xml);
		}
		init();
	}

	private void init() {
		
		name = itemXml.getElementsByTagName("name").item(0).getChildNodes().item(0).getNodeValue();
		itemLevel = itemXml.getElementsByTagName("itemLevel").item(0).getChildNodes().item(0).getNodeValue();
		/*
		icon = item.getIcon().toString();
		heroic = item.getHeroic();
		overallQualityId = "";
		bonding = item.getBonding();
		classId = "" + item.getClassId();
		equipData = item.getEquipData().getSubclassName();
		damageData = item.getDamageData();
		bonusStrength = item.getBonusStrength();
		bonusStamina = "" + item.getBonusStamina();
		// ca ca renvoie null normalement car 
		// il attaque la mauvaise armor du xsd
		armor = item.getArmor().getBase();
		socketData = item.getSocketData();
		durability = item.getDurability();
		requiredLevel = "" + item.getRequiredLevel();
		
		bonusDefenseSkillRating = item.getBonusDefenseSkillRating();
		bonusHitRating = "" + item.getBonusHitRating();
		bonusDodgeRating = item.getBonusDodgeRating();
		itemSource = item.getItemSource();
		*/
	}
	

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public String getIcon() {
		return icon;
	}

	public String getHeroic() {
		return heroic;
	}

	public String getOverallQualityId() {
		return overallQualityId;
	}

	public String getBonding() {
		return bonding;
	}

	public String getClassId() {
		return classId;
	}

	public String getEquipData() {
		return equipData;
	}

	public String getDamageData() {
		return damageData;
	}

	public String getBonusStrength() {
		return bonusStrength;
	}

	public String getBonusStamina() {
		return bonusStamina;
	}

	public String getArmor() {
		return armor;
	}

	public String getSocketData() {
		return socketData;
	}

	public String getDurability() {
		return durability;
	}

	public String getRequiredLevel() {
		return requiredLevel;
	}

	public String getItemLevel() {
		return itemLevel;
	}

	public String getBonusDefenseSkillRating() {
		return bonusDefenseSkillRating;
	}

	public String getBonusHitRating() {
		return bonusHitRating;
	}

	public String getBonusDodgeRating() {
		return bonusDodgeRating;
	}

	public String getItemSource() {
		return itemSource;
	}


}
